package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.LeaseRealHandleDeviceInfo;
import java.util.ArrayList;
import java.util.List;

public class LeaseActualAdapter<T> extends BaseAdapter {

  private List<T> objects = new ArrayList<>();

  private Context context;
  private LayoutInflater layoutInflater;

  //private Callback mCallback;
  public LeaseActualAdapter(Context context, ArrayList<T> objects) {
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    this.objects = objects;
    //this.mCallback=callback;
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = layoutInflater.inflate(R.layout.adapter_simple4, parent, false);
      convertView.setTag(new ViewHolder(convertView));
    }

    initializeViews(getItem(position), (ViewHolder) convertView.getTag());

    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder) {
    LeaseRealHandleDeviceInfo item = (LeaseRealHandleDeviceInfo) object;
    holder.tv1.setText(context.getString(R.string.equipmentType2ColonHolder, item.getDeviceType()));
    holder.tv2.setText(context.getString(R.string.handleStaffColonHolder,
        String.valueOf(item.getHandleStaffName())));
    holder.tv3.setText(
        context.getString(R.string.handleTimeColonHolder, String.valueOf(item.getHandleDate())));
    holder.tv4.setText(
        context.getString(R.string.validTilColonHolder, String.valueOf(item.getValidTil())));
  }

  protected class ViewHolder {
    @BindView(R.id.tv1) TextView tv1;
    @BindView(R.id.tv2) TextView tv2;
    @BindView(R.id.tv3) TextView tv3;
    @BindView(R.id.tv4) TextView tv4;
    //@BindView(R.id.tv_money)
    //TextView tvBottomRight;
    //@BindView(R.id.ll_planStatus)
    //LinearLayout llPlanStatus;

    //@BindView(R.id.tv_cancel)
    //TextView tvCancel;
    //@BindView(R.id.tv_reminder)
    //TextView tvReminder;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }

  public interface Callback {
    void click(View v);
  }
}
